package com.example.high_slope_electronic_sand_table.common.config;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdScalarSerializer;
import java.io.IOException;
import java.text.DecimalFormat;
 
public class CustomFloatSerializer extends StdScalarSerializer<Float> {
    private DecimalFormat df = new DecimalFormat("0.00");
 
    public CustomFloatSerializer() {
        super(Float.class);
    }
 
    @Override
    public void serialize(Float value, JsonGenerator gen, SerializerProvider provider) throws IOException {
        if (value != null) {
            String formattedValue = df.format(value);
            gen.writeNumber(Float.valueOf(formattedValue));
        }
    }
}